package com.fg.cloud.manager.service.system.impl;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fg.cloud.manager.entry.BaseEntity;
import com.fg.cloud.manager.entry.system.SystemUserEntity;
import com.fg.cloud.manager.entry.system.vo.SystemUserVo;
import com.fg.cloud.manager.mapper.BaseMapper;
import com.fg.cloud.manager.mapper.system.SystemUserMapper;
import com.fg.cloud.manager.service.BaseServiceImpl;
import com.fg.cloud.manager.service.system.SystemUserService;

/**
 * Description:系统用户service实现
 * @author dingjiang
 * @date 2017年10月19日下午1:44:49
 */
@Service
public class SystemUserServiceImpl extends BaseServiceImpl implements SystemUserService{

	@Autowired
	private SystemUserMapper systemUserMapper;
	
	@Override
	protected <T extends BaseEntity> BaseMapper getBaseMapper() {
		return systemUserMapper;
	}
	
	/**
	 * 根据系统用户名查询系统用户信息
	 */
	@Override
	public SystemUserVo selectUserByUserName(String userName) {
		return systemUserMapper.selectUserByUserName(userName);
	}

	/**
	 * 验证用户名是否唯一
	 */
	@Override
	public boolean verifyUniquely(String userName) {
		return systemUserMapper.verifyUniquely(userName) > 0 ? true : false;
	}

	/**
	 * 用户注册
	 */
	@Override
	@Transactional
	public boolean register(SystemUserEntity user) {
		//用户密码使用md5加密
		user.setPassword(DigestUtils.md5Hex(user.getPassword()));
		int flag = systemUserMapper.insertSelective(user);
		
		return flag > 0 ? true : false;
	}

	

}
